<template>
  <view class="wrap">
    <view class="hd">
      <view class="icon">
        <image src="../../static/time.png" class="img"></image>
      </view>
      <view class="font">待付款</view>
    </view>
    <view class="user">
      <view class="avatar">
        <image :src="setUrl(user.avatar)" mode="aspectFill" class="img"></image>
      </view>
      <view class="right">
        <view class="title">{{ user.nickname }}</view>
        <view class="coin">{{ params.coin }}投研币</view>
      </view>
    </view>
    
    <view class="footer">
      <view class="desc">合计：<text class="red">{{ params.coin }}</text> 投研币</view>
      <view class="last">当前账户余额{{ userInfo.coin }}投研币</view>
      <button class="btn" hover-class="none" v-if="params.coin > userInfo.coin" @click="goMoneyUp">余额不足，去充值</button>
      <button class="btn" hover-class="none" v-else @click="goPay">去支付</button>
      <uv-safe-bottom></uv-safe-bottom>
    </view>
  </view>
</template>

<script setup>
import { ref, computed } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { post } from '@/api';
import { useUser, useOrder } from '@/store';
import { setUrl, division, toast, mul, getGroup, getUser } from '@/common';

let id = '';
let params = '';
let type = '';
let user = ref({});
const userInfo = computed(() => {
  const store = useUser();
  return store.userInfo;
});

onLoad((option) => {
  params = JSON.parse(option.params);
  type = option.type;
  user.value = uni.getStorageSync('user');
  uni.removeStorageSync('user');
  console.log(params);
  console.log(user.value);
})

function goPay(){
  let url = type == 'theme' ? 'api/association_theme/themeReward' : 'api/association_answer/answerReward';
  post(url, params).then(res => {
    if(res.code == 1){
      getUser();
      uni.redirectTo({
      	url: '/pages/success'
      });
    }
  })
}
function goMoneyUp(){
  uni.navigateTo({
    url: '/pages/mine/money/topup',
  });
}
</script>

<style lang="scss" scoped>
  .footer{
    width: 100%;
    position: fixed;
    left: 0;
    bottom: 0;
    background-color: #fff;
    padding: 30rpx;
    .last{
      font-weight: 400;
      font-size: 24rpx;
      color: rgba(43, 43, 43, 0.46);
      text-align: center;
      padding-top: 17rpx;
      padding-bottom: 50rpx;
    }
    .desc{
      color: #2b2b2b;
      font-size: 28rpx;
      text-align: center;
      .red{
        color: #e43222;
        font-weight: 600;
      }
    }
    .btn{
      width: 432rpx;
      height: 72rpx;
      line-height: 72rpx;
      margin: 0 auto;
    }
  }
  .case{
    padding: 0 30rpx;
    padding-top: 26rpx;
    display: flex;
    align-items: center;
    .input{
      height: 72rpx;
      background: #FFFFFF;
      border: 1rpx solid #E8E8E8;
      border-radius: 4rpx;
      flex: 1;
    }
    .font{
      font-weight: 400;
      font-size: 26rpx;
      color: #797979;
      line-height: 60rpx;
    }
  }
  .integral{
    font-weight: 400;
    font-size: 22rpx;
    color: #E43222;
    line-height: 60rpx;
    padding: 0 30rpx;
    padding-top: 20rpx;
  }
  .disWord{
    font-weight: 400;
    font-size: 26rpx;
    color: #797979;
    line-height: 60rpx;
    padding: 0 30rpx;
    padding-top: 20rpx;
  }
  .line{
    padding: 0 30rpx;
    width: 100%;
  }
  .user{
    padding: 0 30rpx;
    padding-bottom: 50rpx;
    display: flex;
    align-items: center;
    .right{
      padding-left: 20rpx;
      .coin{
        font-weight: 400;
        font-size: 26rpx;
        color: #E43222;
      }
      .title{
        font-weight: 400;
        font-size: 32rpx;
        color: #2B2B2B;
        padding-bottom: 10rpx;
      }
    }
    .avatar{
      width: 100rpx;
      height: 100rpx;
      border-radius: 10rpx;
      overflow: hidden;
    }
  }
  .hd{
    padding: 0 30rpx;
    width: 100%;
    display: flex;
    align-items: center;
    padding-top: 45rpx;
    padding-bottom: 26rpx;
    .font{
      font-weight: 500;
      font-size: 30rpx;
      color: #000000;
      padding-left: 15rpx;
    }
    .icon{
      width: 30rpx;
      height: 30rpx;
      font-size: 0;
    }
  }
</style>